package com.ruyuan.ingestion.config;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;

public class Configuration {
    public static String HBASE_TABLE = "events_db:users";
    public static String BROKERS = "hadoop5:9092";
    public static Integer REDIS_PORT = 6379;
    public static String HOST = "hadoop5";
    public static String STATE = "state";
    public static String HOSTNAME = "hadoop5";
    public static String ZOOKEEPER_PORT = "2181";
    public static String ZOOKEEPER_URL = "hadoop5:2181";

    //hdfs的配置
    public static String CORE_SITE = "coreSite";
    public static String HDFS_SITE = "hdfsSite";
    public static String HBASE_SITE = "hbaseSite";

    /**
     * 解析 settings.xml
     * */
    public static Properties loadSettings(String file) throws IOException {
        Properties properties = new Properties();
        FileInputStream inputStream = new FileInputStream(file);
        try {
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
            try {
                String line = bufferedReader.readLine();
                String[] kv = line.split("=", -1);
                if (kv !=null && kv.length ==2) {
                    properties.put(kv[0],kv[1]);
                }
                line = bufferedReader.readLine();
            }finally {
                bufferedReader.close();
            }
        }finally {
            inputStream.close();
        }
        return properties;
    }
}
